package com.googlecode.milib.display {
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.geom.Matrix;

	/**
	 * @author Marek Brun
	 */
	public class RepeatBitmap extends MovieClip {

		private var bd:BitmapData;
		
		public function RepeatBitmap() {
			
		}

		public function setSourceBitmapData(bd:BitmapData):void {
			this.bd=bd;
		}
		
		public function setSize(newWidth:Number, newHeight:Number):void {
			if(!bd){
				throw new Error('Please setup source bitmap data with method "setSourceBitmapData"');
			}
			
			graphics.clear();
			graphics.beginBitmapFill(bd, new Matrix(), true, false);
			graphics.moveTo(0, 0);
			graphics.lineTo(newWidth, 0);
			graphics.lineTo(newWidth, newHeight);
			graphics.lineTo(0, newHeight);
			graphics.lineTo(0, 0);
			graphics.endFill();
		}
		
		public function getSourceBitmapData():BitmapData {
			return bd;
		}
	}
}
